file_true = 0
file_f = 0
# 定义time，可能以后会用到
import time
import os

os.system("clear")
print("欢迎使用words 3.0")

while True:
    # 
    os.system("clear")
    print("欢迎使用words 3.0（“回车”切换；“y”确认选择）")
    print(">打开")
    print(" 输入")
    open_input = input()
    if open_input == "yes" or open_input == "y" or open_input == "Y":
        file_true = 0
        file_f = 0
        # print("open")
        # 打开文件名
        filelist=os.listdir()
        open_file = input("请输入您要打开的文件名称：")
        # 设置文件为只读
        file_dict = {}
        with open(open_file, encoding="utf-8") as open_read:
          # 参考 https://blog.csdn.net/qq_44787943/article/details/104566951
           for line in open_read.readlines():
               # 识别一行，作为一段
              line = str(line).replace("\n", "")
              # 括号中，前面是分隔符，后面是几个，n + 1 个
              file_dict[line.split(" ", 1)[0]] = line.split(" ", 1)[1]
           open_read.close()
           print("现在，考试开始！")
           for a in range(len(file_dict)):
                file_dict_k = list(file_dict.keys())
                file_input = input("%s :" % file_dict_k[a])
                file_dict_v = list(file_dict.values())
                if file_input == file_dict_v[a]:
                    print("回答正确！")
                    file_true += 1
                else:
                    print("回答错误！")
                    file_f += 1
        input("考试结束，您一共做对了 %d 个题目，做错了 %d 个题目，回车退出. . ." % (file_true, file_f))
        break
    # 
    os.system("clear")
    print("欢迎使用words 3.0（“回车”切换；“y”确认选择）")
    print(" 打开")
    print(">输入")
    input_input = input()
    if input_input == "yes" or input_input == "y" or input_input == "Y":
        os.system("clear")
        words_number = int(input("请输入您考单词的个数："))
        input_time_number = 0
        english_dictionary = {}
        chinese_dictionary = {}
        #
        reply_true = 0
        reply_error = 0
        reply_error_dictionary_chinese = {}
        reply_error_dictionary_english = {}
        #
        for i in range(words_number):
            os.system("clear")
            input_time_number += 1
            print("第 %d 个" % input_time_number)
            chinese_input = input("请输入显示内容：")
            english_input = input("请输入用户需要输入的内容：")
            chinese_dictionary[input_time_number] = chinese_input
            english_dictionary[input_time_number] = english_input
        input_time_number = 0
        for i in range(words_number):
            os.system("clear")
            input_time_number += 1
            print("----------考试进行中----------")
            use_input = input(chinese_dictionary[input_time_number] + ":")
            if use_input == english_dictionary[input_time_number]:
                print("回答正确")
                reply_true += 1
                input()

            else:
                print("回答错误")
                reply_error += 1
                reply_error_dictionary_chinese[reply_error] = chinese_dictionary[input_time_number]
                reply_error_dictionary_english[reply_error] = english_dictionary[input_time_number]
                input()
            os.system("clear")
        while True:
            os.system("clear")
            print("考试完成，一共正确了 %d 个，错误了 %d 个。是否进加强考试？（“回车”切换；“y”确认选择）" %(reply_true, reply_error))
            print(">加强考试")
            print(" 退出")
            Retake_1  = input()
            if Retake_1 == "yes" or Retake_1 == "y" or Retake_1 == "Y":
                os.system("clear")
                two_T = 0
                two_F = 0
                reply_error_repeat = reply_error
                reply_error = 0
                for i in range(reply_error_repeat):
                    print("----------加强考试进行中----------")
                    reply_error += 1
                    repeat = input(reply_error_dictionary_chinese[reply_error] + ":")
                    if repeat == reply_error_dictionary_english[reply_error]:
                        print("回答正确")
                        two_T += 1
                    else:
                        print("回答错误")
                        two_F += 1
                input("考试结束，正确 %d 个，错误 %d 个，回车推出" % (two_T, two_F))
                break
            os.system("clear")
            print("考试完成，一共正确了 %d 个，错误了 %d 个。是否进加强考试？（“回车”切换；“y”确认选择）" %(reply_true, reply_error))
            print(" 加强考试")
            print(">退出")
            Retake_2 = input()
            if Retake_2 == "yes" or Retake_1 == "y" or Retake_1 == "Y":
                quit()
        break
